const axios = require('axios');

const BASE_URL = 'http://localhost:3001';

// 调试管理员登录
async function debugAdminLogin() {
  console.log('调试管理员登录...');
  
  const credentials = {
    adminname: 'admin',
    password: '123456'
  };
  
  console.log('发送登录请求:', credentials);
  
  try {
    const response = await axios.post(`${BASE_URL}/admin/admin/login`, credentials, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    
    console.log('\n=== 响应信息 ===');
    console.log('状态码:', response.status);
    console.log('响应头:', response.headers);
    console.log('响应数据:', JSON.stringify(response.data, null, 2));
    
    if (response.data.code === '200') {
      console.log('\n✓ 登录成功!');
      console.log('Token:', response.data.data.token.substring(0, 50) + '...');
    } else {
      console.log('\n✗ 登录失败:', response.data.message);
    }
    
  } catch (error) {
    console.error('\n❌ 请求失败:', error.message);
    if (error.response) {
      console.error('错误状态码:', error.response.status);
      console.error('错误响应:', error.response.data);
    }
  }
}

// 运行调试
if (require.main === module) {
  debugAdminLogin();
}